home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / Classes / browser / BrowserBay.m < prev    next >
Text File  |  1995-06-12  |  6KB  |  295 lines

  1. #import "BrowserBay.h"
  2. #import "BrowserMatrix.h"
  3. #import <objc/List.h>
  4. #import <appkit/appkit.h>
  5. #import <streams/streams.h>
  6. #import <sys/types.h>
  7. #import <sys/stat.h>
  8. #import <sys/file.h>
  9. #import <stdio.h>
  10. #import <math.h>
  11.  
  12. #define FIELDHEIGHT 21.0
  13. #define SCROLLERHEIGHT 18.0
  14. #define INTERPANEL 2.0
  15.  
  16. extern char *strcpy(), *strcat();
  17.  
  18. @implementation BrowserBay
  19.  
  20. static id make_button (NXRect *rect, SEL action, id target)
  21. {
  22.     id button;
  23.     
  24.     button = [Button newFrame:rect
  25.              title:NULL
  26.              tag:0
  27.              target:target
  28.              action:action
  29.              key:0
  30.              enabled:YES];
  31.     [button setOpaque:NO];
  32.     [button setIconPosition:NX_ICONONLY];
  33.     [button setType:NX_MOMENTARYPUSH];
  34.     [button setContinuous:YES];
  35.     [button setPeriodicDelay:0.4 andInterval:0.1];
  36.     [button setEnabled:YES];
  37.     return button;
  38. }
  39.  
  40. + newFrame:(NXRect *)rect
  41. {
  42.     NXRect r1;
  43.     id box, boldFont, scrollView;
  44.     int rows, i;
  45.     float width;
  46.     char fontname[64];
  47.     
  48.     self = [super newFrame:rect];
  49.     [self setOpaque:YES];
  50.     r1.size.width = rect->size.width;    /* make title header */
  51.     r1.size.height = FIELDHEIGHT;
  52.     r1.origin.x = 0.0;
  53.     r1.origin.y = rect->size.height - r1.size.height;
  54.     bayHeader = [TextField newFrame:&r1];
  55.     [bayHeader setAlignment:NX_CENTERED];
  56.     [bayHeader setBackgroundGray:NX_DKGRAY];
  57.     [bayHeader setTextGray:NX_WHITE];
  58.     [bayHeader setBezeled:YES];
  59.     [bayHeader setSelectable:NO];
  60.     strcpy (fontname, [[bayHeader font] name]);
  61.     strcat (fontname, "-Bold");
  62.     boldFont = [Font newFont:fontname size:[[bayHeader font] pointSize]];
  63.     [bayHeader setFont:boldFont];
  64.     [self addSubview:bayHeader];
  65.     width = rect->size.width / 2.0;
  66.     r1.size.width = floor (width); /* make scroll buttons */
  67.     r1.size.height = SCROLLERHEIGHT;
  68.     r1.origin.x = 0.0;
  69.     r1.origin.y = 0.0;
  70.     downButton = make_button (&r1, @selector(scrollDown:), self);
  71.     [self addSubview:downButton];
  72.     r1.origin.x += width;
  73.     upButton = make_button (&r1, @selector(scrollUp:), self);
  74.     [self addSubview:upButton];
  75.     r1.size.width = rect->size.width;    /* make text box */
  76.     r1.size.height = rect->size.height - 2.0 * INTERPANEL - FIELDHEIGHT -
  77.         SCROLLERHEIGHT;
  78.     r1.origin.x = 0.0;
  79.     r1.origin.y = SCROLLERHEIGHT + INTERPANEL;
  80.     box = [Box newFrame:&r1];
  81.     [box setBorderType:NX_BEZEL];
  82.     [box setOffsets:0.0 :0.0];
  83.     [box setTitlePosition:NX_NOTITLE];
  84.     [self addSubview:box];
  85.     scrollView = [ScrollView new];
  86.     [scrollView setBorderType:NX_NOBORDER];
  87.     [scrollView setHorizScrollerRequired:NO];
  88.     [scrollView setVertScrollerRequired:NO];
  89.     [[box setContentView:scrollView] free];
  90.     [scrollView getContentSize:&r1.size];
  91.     r1.origin.x = r1.origin.y = 0.0;
  92.     bayMatrix = [BrowserMatrix newFrame:&r1];
  93.     [bayMatrix setAction:@selector(touchedEntry:)];
  94.     [bayMatrix setTarget:self];
  95.     [bayMatrix setBackgroundGray:NX_LTGRAY];
  96.     [scrollView setDocView:bayMatrix];
  97.     buttonsEnabled = YES;
  98.     [self updateScrollButtons];
  99.     nextBrowserBay = nil;
  100.     return self;
  101. }
  102.  
  103. - allowEmptySel:(BOOL)flag
  104. {
  105.     [bayMatrix allowEmptySel:flag];
  106.     return self;
  107. }
  108.  
  109. - _matrix
  110. {
  111.     return bayMatrix;
  112. }
  113.  
  114. - addSlave:aBrowserBay
  115. {
  116.     [bayMatrix addSlave:[aBrowserBay _matrix]];
  117.     return self;
  118. }
  119. - entryAt:(int)row
  120. {
  121.     return [bayMatrix cellAt:row :0];
  122. }
  123.  
  124. - findEntryWithText:(const char *)text
  125. {
  126.     int i, count;
  127.     id cells, aCell;
  128.     
  129.     count = [bayMatrix cellCount];
  130.     cells = [bayMatrix cellList];
  131.     for (i = 0; i < count; i++) {
  132.         aCell = [cells objectAt:i];
  133.         if (strcmp ([aCell stringValue], text) == 0) return aCell;
  134.         }
  135.     return nil;
  136. }
  137.  
  138. - removeEntry:aCell
  139. {
  140.     [bayMatrix removeEntry:aCell];
  141.     return self;
  142. }
  143.  
  144. - (int)getRowOfEntry:entry
  145. {
  146.     int row, col;
  147.     [bayMatrix getRow:&row andCol:&col ofCell:entry];
  148.     return row;
  149. }
  150.  
  151. - selectEntryAt:(int)row
  152. {
  153.     [bayMatrix selectEntryAt:row];
  154.     return self;
  155. }
  156.  
  157. - setButtonsEnabled:(BOOL)flag
  158. {
  159.     buttonsEnabled = flag;
  160.     return self;
  161. }
  162.  
  163. - updateScrollButtons
  164. {
  165.     BOOL upEnabled, downEnabled;
  166.     
  167.     if (!buttonsEnabled) return self;
  168.     upEnabled = [upButton isEnabled];
  169.     downEnabled = [downButton isEnabled];
  170.     if (![bayMatrix atTop] && !upEnabled) {
  171.         [upButton setEnabled:YES];
  172.         [upButton setIcon:"scrollMenuUp" position:NX_ICONONLY];
  173.         }
  174.     if ([bayMatrix atTop] && upEnabled) {
  175.         [upButton setEnabled:NO];
  176.         [upButton setIcon:"scrollMenuUpD" position:NX_ICONONLY];
  177.         }
  178.     if (![bayMatrix atBottom] && !downEnabled) {
  179.         [downButton setEnabled:YES];
  180.         [downButton setIcon:"scrollMenuDown" position:NX_ICONONLY];
  181.         }
  182.     if ([bayMatrix atBottom] && downEnabled) {
  183.         [downButton setEnabled:NO];
  184.         [downButton setIcon:"scrollMenuDownD" position:NX_ICONONLY];
  185.         }
  186.     return self;
  187. }
  188.  
  189. - scrollDown:sender
  190. {
  191.     [bayMatrix scrollDown:sender];
  192.     [self updateScrollButtons];
  193.     return self;
  194. }
  195.  
  196. - scrollUp:sender
  197. {
  198.     [bayMatrix scrollUp:sender];
  199.     [self updateScrollButtons];
  200.     return self;
  201. }
  202.  
  203. - setAlphabetize:(BOOL)flag
  204. {
  205.     [bayMatrix setAlphabetize:flag];
  206.     return self;
  207. }
  208.  
  209. - selectedCell
  210. {
  211.     return [bayMatrix selectedCell];
  212. }
  213.  
  214. - (char *)title
  215. {
  216.     return (char *) [bayHeader stringValue];
  217. }
  218.  
  219. - setTitle:(const char *)title
  220. {
  221.     [bayMatrix clear];
  222.     [bayHeader setStringValue:title];
  223.     [nextBrowserBay setTitle:NULL];
  224.     if (title == NULL) [self display];
  225.     return self;
  226. }
  227.  
  228. - display
  229. {
  230.     [bayMatrix display];
  231.     [super display];
  232.     [self updateScrollButtons];
  233.     return self;
  234. }
  235.  
  236. - addEntry:(const char *)text leaf:(BOOL)yn
  237. {
  238.     [bayMatrix addEntry:text leaf:yn];
  239.     return self;
  240. }
  241.  
  242. - cellList
  243. {
  244.     return [bayMatrix cellList];
  245. }
  246.  
  247. - (int)cellCount
  248. {
  249.     return [bayMatrix cellCount];
  250. }
  251.  
  252. - listFiles:(const char *)dir suffix:(const char *)sfx
  253. {
  254.     [bayMatrix listFiles:dir suffix:sfx];
  255.     return self;
  256. }
  257.  
  258. - setAction:(SEL)selector
  259. {
  260.     action = selector;
  261.     return self;
  262. }
  263.  
  264. - setTarget:anObject
  265. {
  266.     target = anObject;
  267.     return self;
  268. }
  269.  
  270. - setNextBrowserBay:anObject
  271. {
  272.     nextBrowserBay = anObject;
  273.     return self;
  274. }
  275.  
  276. - (int)selectedRow
  277. {
  278.     return [bayMatrix selectedRow];
  279. }
  280.  
  281. - touchedEntry:sender
  282. {
  283.     id aCell;
  284.     
  285.     aCell = [bayMatrix selectedCell];
  286.     if (![aCell isLeaf])
  287.         [nextBrowserBay setTitle:[aCell stringValue]];
  288.     else [nextBrowserBay setTitle:NULL];
  289.     [self sendAction:action to:target];
  290.     return self;
  291. }
  292.  
  293. @end
  294.  
  295.